import java.util.Queue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;

public class demo20 {
    public static void main(String[] args) {
        BlockingQueue<Integer> blockingQueue = new LinkedBlockingQueue<>();

        Thread t1 = new Thread(() -> {
            try {
                while(true){
                    int val = blockingQueue.take();
                    System.out.println("消费val+"+val);
                    System.out.println(val);
                }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t1.start();

        Thread t2 = new Thread(() -> {
            try {
                int val = 0;
               while (true){
                   System.out.println("生产val+"+val);
                   blockingQueue.put(val);
                   val++;
                   Thread.sleep(1000);
               }
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        });
        t2.start();
    }
}
